<template>
  <div>
    <div>
      <van-address-list
        v-model="chosenAddressId"
        :list="list"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
      />
    </div>
  </div>
</template>

<script>
import { reqAddressList } from "../../../http/api";
export default {
  data() {
    return {
      //默认选中的id
      chosenAddressId: "2",
      //1.列表：每条数据的字段不能改
      list: []
    };
  },
  mounted() {
    //2.发请求
    reqAddressList({
      uid: JSON.parse(localStorage.getItem("user")).uid
    }).then(res => {
      var list = res.data.list ? res.data.list : [];
      this.list = list.map(item => {
        return {
          id: item.id,
          name: item.username,
          tel: item.userphone,
          address: item.location + item.useraddress,
          isDefault: item.status === 1
        };
      });
    });
  },
  methods: {
    //点了添加按钮
    onAdd() {
      this.$router.push("/addSite");
    },
    //点了编辑按钮
    onEdit(item, index) {
      this.$router.push("/addSite?id=" + item.id);
    },
    //切换选中
    onSelect(item, index) {
      this.$router.push("/order?addressId=" + item.id);
    }
  }
};
</script>

<style>
</style>